<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>随机取人</title>
    <link rel="stylesheet" href="dist/style/weui.css"/>
    <link rel="stylesheet" href="index.css"/>
    <script src="dist/example/zepto.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="dist/weui.js"></script>
</head>
<body oncontextmenu=self.event.returnValue=false>
<div class="page">
    <div class="weui-form">
        <div class="weui-form__text-area">
            <h2 class="weui-form__title" id="title1"></h2>
        </div>
        <div class="weui-form__control-area">
            <div class="weui-cells__group weui-cells__group_form">
                <div class="weui-cells__title">随机列表</div>
                <div class="weui-cells" id="rlist">

                </div>
            </div>
        </div>
    </div>

    <div class="weui-form__opr-area">
        <a class="weui-btn weui-btn_primary" href="javascript:turnback()" id="showTooltips">返回</a>
        <a href="javascript:deletelist();" class="weui-btn weui-btn_warn">删除此列表</a>
    </div>
</div>
</div>
<script>
    if (window.location.href.split('?')[1] == undefined){
        turnback();
    } else if (window.location.href.split('?')[1].startsWith('id=')) {
        $.ajax({
            type: "post",
            url: "http://39.101.190.160:8000/getlist/",
            async: false,
            dataType: "json",
            data: {
                "id": window.location.href.split('?')[1].split('id=')[1],
            },
            success: function (res) {
                if(res.list.length == 0){
                    turnback();
                }
                for(let i = 0 ; i<res.list.length;i++){
                    document.getElementById('rlist').innerHTML += '<div class="weui-cell "><div class="weui-cell__bd"><p>第' + (i+1) +
                        '项</p></div><div class="weui-cell__ft">' + res.list[i] + '</div></div>';
                }
                document.getElementById('title1').innerHTML = res.name;
            },
            error: function (res) {
                console.log(res);
            },
            complete: function (res) {
            }
        });
    } else {
        turnback();
    }
    function turnback() {
        window.open('viewlist.html','_self');
    }
    function deletelist() {
        weui.confirm('确定要删除此列表吗', {
            title: '提示',
            buttons: [{
                label: '取消',
                type: 'default',
                onClick: function(){

                }
            }, {
                label: '确定',
                type: 'primary',
                onClick: function(){
                    weui.loading('正在删除');
                    $.ajax({
                        type: "post",
                        url: "http://39.101.190.160:8000/deletefile/",
                        async: false,
                        dataType: "json",
                        data: {
                            "id": window.location.href.split('?')[1].split('id=')[1],
                        },
                        success: function (res) {
                            window.open('viewlist.html','_self');
                        },
                        error: function (res) {
                            console.log(res);
                        },
                        complete: function (res) {
                        }
                    });
                }
            }]
        });
    }
</script>
<script Language="JavaScript">
    function click() {
        if (event.button == 2 || event.button == 3) {
            weui.alert('复制用Control+C哦')
        }
    }
    document.onmousedown = click
</script>
</body>
</html>